package com.surprise.bweb.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.surprise.redis.RedisFactory;
import com.surprise.redis.RedisKeyGenerator;

import redis.clients.jedis.Jedis;

/**
 * ShareManager.java
 * @author nick
 * @since 2016年4月3日
 */
@Component
public class ShareManager {
    @Autowired
    private RedisFactory redisFactory;
    
    /**
     * 获得item的计数，并加1
     * @param type
     * @param id
     * @return
     */
    public long shareCount(int type, long id) {
        Jedis jedis = null;
        try {
            jedis = redisFactory.getClient();
            String key = RedisKeyGenerator.generateShareCountKey(type, id);
            return jedis.incr(key);
        } finally {
            redisFactory.returnResource(jedis);
        }
    }
}
